Skip to content

Disallow cookies explicitly - #1447

Merged
kurtmckee merged 2 commits into
mainfrom
disallow-cookies-explicitly
Nov 9, 2026
Merged

kurtmckee merged 2 commits into
mainfrom
disallow-cookies-explicitly

Conversation

@kurtmckee

Copy link
Copy Markdown
Member

Fixed

  • RequestsTransport no longer stores cookies set by responses. (:pr:NUMBER)

    Previously, a cookie set by one response could be sent on a later, unrelated request
    that was redirected, if the client or transport was shared.

@sirosen

sirosen commented Nov 7, 2026

Copy link
Copy Markdown
Member

I'm not convinced.
A transport contains a session and therefore has the characteristic properties of "object containing a session".

Can you explain what you were doing such that this was an issue? Or otherwise some theoretical mode of interaction in which this is problematic?

Note that subclassing SDK base classes to communicate with customer run services is a supported use case. So even if we were aligned that this should change, I think we need to discuss whether or not it waits for a major release.

@kurtmckee

kurtmckee commented Nov 7, 2026 •

Copy link
Copy Markdown
Member Author

The core issue is the misalignment of session state leaking into the request only if a redirect occurs.

The current code uses request.prepare() (as opposed to session.prepare_request(), which avoids session state on the first request.

If a redirect occurs, requests will re-prepare with session state into the follow-up request.

I'm open to a different fix, but I'd like to ensure that hosts cannot set session state (specifically, cookies) that leaks out on redirects.

@kurtmckee

Copy link
Copy Markdown
Member Author

I should clarify what I wrote.

When the SDK prepares a request, it never uses the session's cookie jar because the transport sends request.prepare() and not session.prepare_request(). A manually-set Cookie header can still go out on the first hop.

The session jar is only read when requests follows a redirect. This PR stops the jar from storing response cookies, so a cookie set by request 1 can no longer be replayed on a redirected request 2. Cookies set within a single redirect chain still work.

This is a correctness concern for shared clients and transports.

@sirosen

sirosen commented Nov 7, 2026

Copy link
Copy Markdown
Member

Okay, this totally changes my understanding of the issue! Given my own misunderstanding, I think it's likely that someone else reading the changelog could also be confused.

I did not grasp that this behavior is specific to redirected requests. Yes, the change is that we no longer store the cookie, but the effect is not that "we disabled cookies" or any such generic change in behavior.

Would it be accurate to phrase things like so?

This only impacts requests following redirects. Previously, a redirected request could find and use stored cookies, whereas requests with no redirect would not.

@kurtmckee

Copy link
Copy Markdown
Member Author

Rephrasing the changelog fragment seems worthwhile. I've drafted this:

Fixed
-----

- Fix session cookies being stored and sent on redirected requests. (:pr:`NUMBER`)

  Previously, the SDK would not send session cookies when making an HTTP request,
  but if the request was subsequently redirected then session cookies could be added.

  Now, ``RequestsTransport`` no longer stores cookies set by responses.

Would that clarify the situation?

@sirosen

sirosen commented Nov 9, 2026

Copy link
Copy Markdown
Member

Yep, that phrasing is excellent, and clear to me! I'm about to crack things open and read through the implementation.

Comment thread src/globus_sdk/transport/_no_cookies.py Outdated
"""

# the attributes which `http.cookiejar.CookieJar` reads from its policy
netscape = True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is netscape = True set, when the others are false? It stands out, so I'm curious.

"no cookies" suggests to me that all three flags should be false.
I tried flipping this to netscape = False and the testsuite passed in my runs.

Is there some knock-on effect of turning all three off?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CookiePolicy defines some methods that all subclasses should override. However, the subclass DefaultCookiePolicy sets several instance variables that other places in the standard library access as attributes.

These class variables exist solely to prevent AttributeError from elsewhere within the standard library. Their values don't have a functional purpose, but it'll be clearer if they all say False, rather than happening to match the defaults set by DefaultCookiePolicy.

I'll update this.

@kurtmckee
kurtmckee force-pushed the disallow-cookies-explicitly branch from 790e319 to 977996a Compare November 9, 2026 21:46

@sirosen sirosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change and deserves more than a rote approval!

Here's a nice bit of architecture trivia, as payment for your good work:
https://en.wikipedia.org/wiki/Mullion

Image

@kurtmckee
kurtmckee merged commit 7d91693 into main Nov 9, 2026
12 checks passed
@kurtmckee
kurtmckee deleted the disallow-cookies-explicitly branch November 9, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants